package com.smartwasser.yunhtgl.apphtgl.presenter;

import android.os.Handler;

import com.smartwasser.yunhtgl.apphtgl.bean.SP3Bean;
import com.smartwasser.yunhtgl.apphtgl.network.RetrofitApi;
import com.smartwasser.yunhtgl.apphtgl.network.Retrofits;
import com.smartwasser.yunhtgl.apphtgl.view.SP03View;
import com.smartwasser.yunhtgl.apphtgl.utils.Logger;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class SP03PresenterImpl implements SP03Presenter {
    private SP03View sp03View;
    private Handler mHandler = new Handler();

    public SP03PresenterImpl(SP03View sp03View) {
        this.sp03View = sp03View;
    }

    @Override
    public void getType1SP03(String JSESSIONID, int pageNo, String category, String procurementMode, String moneyRange) {
        Retrofits.getInstance().createReq(RetrofitApi.class).getType1Sp2(JSESSIONID, pageNo, category, procurementMode, moneyRange, 10)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<SP3Bean>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                sp03View.error();
                Logger.e("onError");
            }

            @Override
            public void onNext(final SP3Bean typeSP3Bean) {
                sp03View.success(typeSP3Bean);
                Logger.e("onNext");
            }
        });
    }
}
